package cn.itwangxiang.android.ui;

import cn.itwangxiang.android.R;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ToggleButton;

public class DemoBaiduMap extends Activity {

	private BaiduMap mBaiduMap;

	private MapView mMapView = null;

	private CheckBox checkBox = null;

	private ToggleButton toggleButton = null;

	private Button button = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_baidumap);

		mMapView = (MapView) findViewById(R.id.bmapView);

		mBaiduMap = mMapView.getMap();

		checkBox = (CheckBox) findViewById(R.id.checkBox1);
		checkBox.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (checkBox.isChecked()) {
					// 卫星地图
					mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
				} else {
					// 普通地图
					mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
				}
			}
		});

		toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);
		toggleButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (toggleButton.isChecked()) {
					// 开启交通图
					mBaiduMap.setTrafficEnabled(true);
				} else {
					// 关闭交通图
					mBaiduMap.setTrafficEnabled(false);
				}

			}
		});

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		// 在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
		mMapView.onDestroy();
	}

	@Override
	protected void onResume() {
		super.onResume();
		// 在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
		mMapView.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		// 在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
		mMapView.onPause();
	}

}
